package cn.taleo.common.mybatis;

import cn.taleo.common.entity.TestEntity;
import cn.taleo.common.utils.ReflectionUtils;
import com.alibaba.druid.sql.visitor.functions.Insert;
import org.apache.ibatis.jdbc.SQL;


import java.util.HashMap;
import java.util.Map;

public class BaseProvider {

    public static String save(Map<String,Object> map){
        Object obj = map.get("obj");
        String table = (String)map.get("table");
        SQL sql = new SQL() {
            {
                INSERT_INTO(table);
                VALUES(ReflectionUtils.fatherAndSonFeild(obj), ReflectionUtils.fatherAndSonFeildValue(obj));
            }
        };
        return sql.toString();
    }


    public static void main(String[] args) throws Exception{
        HashMap<String, Object> map = new HashMap<>();
        TestEntity testEntity = new TestEntity();
        testEntity.setOpenId("123");
        testEntity.setUserName("zhangsan");
        map.put("obj",testEntity);
        map.put("table","testEntity");
        String save = save(map);
        System.out.println(save);

    }
}
